import { MessagePlugin, NotifyPlugin, DialogPlugin } from 'tdesign-vue'
import settings from '@/settings.js'

const utilMessage = {
  //成功
  success(msg, durationParam) {
    if (!durationParam) durationParam = settings.messageDuration
    MessagePlugin.success({ content: global.strings.replaceBr(msg), duration: durationParam, placement: 'top', closeBtn: true, zIndex: 9999991})
  },
  //错误
  error(msg, duration = settings.errorMessageDuration) {
    MessagePlugin.error({ content: global.strings.replaceBr(msg), duration: duration, placement: 'top', closeBtn: true, zIndex: 9999991})
  },
  //警告
  warning(msg, durationParam) {
    if (!durationParam) durationParam = settings.errorMessageDuration
    MessagePlugin.warning({ content: global.strings.replaceBr(msg), duration: durationParam, placement: 'top', closeBtn: true, zIndex: 9999991})
  },
  //信息
  info(msg) {
    MessagePlugin.info({ content: global.strings.replaceBr(msg), duration: settings.messageDuration, placement: 'top', closeBtn: true, zIndex: 9999991})
  },

  //通知
  /**
   * @Description：系统通知，全局唯一
   * @Date 2023-10-21
   * @param title   提示标题
   * @param content 提示内容
   * @param btnShow 右下角显示操作按钮
   * @param btnCall 右下角按钮事件
   * @param btnText 右下角按钮文字
  */
  notifyHome(title = '系统通知',subTitle = '', content, btnShow = false, btnCall,  btnText = '查看详情') {
    let home = global.vue.$children[0].$children[0]
    home.notificationHome.title = title
    home.notificationHome.subTitle = subTitle
    home.notificationHome.content = content
    home.notificationHome.btnText = btnText
    home.notificationHome.btnShow = btnShow
    home.notificationHome.btnCall = btnCall
    home.notificationHome.show = true
  },

  /**
   * @Description：确认框 只有确认、取消按钮
   * @Author wyt
   * @Date 2023-04-27
   * @param msg  提示信息
   * @param confirmFun 确认回调函数
   * @param cancelFun 取消回调函数
   */
  confirm(msg, confirmFun, cancelFun) {
    let home = global.vue.$children[0].$children[0]
    home.$refs.customDialogConfirm.show(msg, () => {
      if (confirmFun) {
        confirmFun()
      }
    }, () => {
      if (cancelFun) {
        cancelFun()
      }
    })
  },

  /**
   * @Description：确认框带输入框
   * @Author wyt
   * @Date 2023-04-27
   * @param title  提示标题
   * @param confirmFun 确认回调函数
   */
  confirmInput(title = '系统提示', confirmFun) {
    let home = global.vue.$children[0].$children[0]
    home.confirmInputForm.title = title
    home.confirmInputForm.confirmFun = confirmFun
    home.$refs.confirmInputDrawer.show()
    home.$refs.confirmInputFormRemark.focus()
  },

  /**
   * @Description：提示框-失败
   * @Author wyt
   * @Date 2023-04-27
   * @param msg  提示信息
   * @param confirmFun 确认回调函数
   */
  alertFail(msg, confirmFun) {
    let home = global.vue.$children[0].$children[0]
    if (!home || !home.$refs.customAlertFail) {
      const confirmDia = DialogPlugin.confirm({
        header: '系统提示',
        body: msg,
        confirmBtn: '确定',
        cancelBtn: null,
        onConfirm: ({ e }) => {
          if (confirmFun) {
            confirmFun()
          }
          confirmDia.hide();
        },
        onClose: ({ e, trigger }) => {
          confirmDia.hide();
        },
      })
      return
    }

    home.$refs.customAlertFail.show(msg, () => {
      if (confirmFun) {
        confirmFun()
      }
    })
  },

  /**
   * @Description：提示框-成功
   * @Author wyt
   * @Date 2023-04-27
   * @param msg  提示信息
   * @param confirmFun 确认回调函数
   */
  alertSuccess(msg, confirmFun) {
    let home = global.vue.$children[0].$children[0]
    home.$refs.customAlertSuccess.show(msg, () => {
      if (confirmFun) {
        confirmFun()
      }
    })
  }
}

setTimeout(() => {
  // utilMessage.notifyHome('系统通知', '内容11111111')
}, 5000)

export default utilMessage
